import requests
from config import BASE_URL
from common.get_headers import get_headers
from common.log_util import init_logger


logger=init_logger()
class EmpApi(object):
    # path = "/api/sys/user"

    @classmethod
    def add_emp(cls,headers,body):
        """添加员工接口"""
        url = f"{BASE_URL}/api/sys/user"
        logger.debug(f'url信息：{url}')
        logger.debug(f'请求头：{headers}')
        resp = requests.post(url, headers=headers, json=body)  #发送请求
        logger.debug(f'响应体：{resp.json()}')
        return resp

    @classmethod
    def get_emp(cla,headers,id):
        """查询员工接口"""
        url = f"{BASE_URL}/api/sys/user" + "/" +id
        resp = requests.get(url,headers=headers)
        return resp


    @classmethod
    def xg_emp(cla,headers,id,body):
        """修改员工接口"""
        url = f"{BASE_URL}/api/sys/user" + "/" + id
        resp = requests.put(url,headers=headers,json=body)
        return resp

    @classmethod
    def delete_emp(cla, headers, id):
        """删除员工接口"""
        url = f"{BASE_URL}/api/sys/user" + "/" + id
        resp = requests.delete(url, headers=headers)
        return resp




if __name__ == '__main__':
    #添加员工
    headers = get_headers()
    body_add = {"username":"沸羊羊","mobile": "13211192222", "workNumber": "1233456"}
    resp = EmpApi.add_emp(headers,body_add)
    id = resp.json().get('data').get('id')
    print(resp.json())

    #修改员工
    body_xg = {"username": "喜羊羊", "password": "112211", "departmentId": "131214"}
    resp = EmpApi.xg_emp(headers,id,body_xg)
    id = resp.json().get('data').get('id')
    print(resp.json())

    #删除员工
    resp_delete = EmpApi.delete_emp(headers,id)
    print('删除员工:',resp_delete.json())